import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;


public class Main {

    static final int N = 100010;
    static int[] s = new int[N];
    static int n;
    static long res;

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StreamTokenizer in = new StreamTokenizer(br);
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 1; i <= n; i++) {
            s[i] = nextInt();
            s[i] += s[i - 1];
        }

        int cnt = 0;
        if (n < 3 || s[n] % 3 != 0) {
            out.println(0);
        } else {
            for (int i = 2; i <= n - 1; i++) {
                if (s[i - 1] == s[n] / 3) cnt++;
                if (s[i] == s[n] * 2 / 3) res += cnt;
            }
            out.println(res);
        }
        out.flush();
    }

    package Day_Day_work;

import java.util.HashSet;
import java.util.Set;

   /
/*
1、HashSet去重
2、Set.retailAll(s2)方法判断两数中是否存在有重复的数
3、注意强制类型的转换
 */
    public class 排它平方数
    {
        public static void main(String[] args) {
            for (int i=100000;i<1000000;i++){
                if(B(i)){
                    if(i!=203879 ) System.out.println(i);
                }
            }
        }
        public static Set A(long m){//去重
            String s=""+m;
            Set h=new HashSet<>();
            for (int i=0;i<s.length();i++){
                h.add(s.charAt(i));
            }
            return h;
        }
        public static boolean B(int n){
            Set s1=A(n);
            Set s2=A((long)n*n);//强制转换成long
            if(s1.size()!=6)return false;
            s1.retainAll(s2);
            return s1.isEmpty();
        }
    }

}
